#ifndef _CROSSENGINE_CLIENT_H_
#define _CROSSENGINE_CLIENT_H_
#include "container.h"
#include "network.h"
#include "crossobject.h"
class NetPacket;
class INetFilter;
class GamePlayer;
class IMsgHandler;

std::string CrossGetPeerDotip(CrossSock s);

class Client:public Connection,public CrossObject
{
public:
    ~Client();
    explicit Client(CrossSock s);
    void OnRecvNetPacket(const NetPacket& pack);
    void SendNetPacket(NetPacket& pack);
    void SetFilter(INetFilter* filter);
    void AttachPlayer(GamePlayer* player);
    void DetachPlayer();
    GamePlayer* GetPlayer(){return _player;}
    void ActiveCloseMe();
private:
    INetFilter* _filter;
    GamePlayer* _player;
};

class ClientManager
{
public:
    virtual ~ClientManager();
    virtual Client* CreateClient(CrossSock s);
    virtual Crypter* CreateCrypter();
    virtual IMsgHandler* CreateMsgHandler();
    bool Add(CrossSock s,Client* client);
    Client* Remove(CrossSock s);
    Client* Find(CrossSock s);
private:
    Cross::HashMap<CrossSock,Client*> _clients;
};

void CrossMultiSendNetPacket(MultiCrossSock* multiSock,NetPacket& pack);

#endif//_CROSSENGINE_CLIENT_H_
